package com.Imp;

import com.entity.Merchant;
import com.mapper.MerchantMapper;
import com.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

public class MerchantMapperImpl implements MerchantMapper {
    public Merchant getMerchantBymerchantId(String merchantId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            Map<String, Object> param = new HashMap<>();
            param.put("userName", merchantId);
            return sqlSession.selectOne("com.mapper.MerchantMapper.getMerchantBymerchantId", merchantId);
        }
    }
    public void addMerchant(Merchant merchant){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.MerchantMapper.addMerchant", merchant);
            sqlSession.commit();
        }
    }
    public void updateMerchant(Merchant merchant){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.update("com.mapper.MerchantMapper.updateMerchant", merchant);
            sqlSession.commit();
        }
    }
    public void deleteMerchant(String merchantId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.delete("com.mapper.MerchantMapper.deleteMerchant", merchantId);
            sqlSession.commit();
        }
    }


}
